package leetcode.简单;

import org.junit.Test;

public class leetcode283_移动零 {


    @Test
    public void test(){
        int[] nums = new int[]{4,2,4,0,0,3,0,5,1,0};
        moveZero(nums);
        for (int n:nums){
            System.out.println(n+"");
        }
    }


    /**
     * 每当遇到0时整体除了0左移
     * @param nums
     */
    public void moveZeroes(int[] nums) {

        for(int i = 0; i<nums.length ;i++){
            if(nums[i]==0){
                int temp;
                for(int j = 0,n=j+1; n<=nums.length-1;j++,n++){
                    if (nums[j]==0){
                        temp = nums[j];
                        nums[j] = nums[n];
                        nums[n] = temp;
                    }
                }
            }
        }
    }

    /**
     * 不是0的全部左移
     */

    public void moveZero(int[] nums){
        int temp;
        for(int i = 0; i<= nums.length-1;i++){

            for(int j = 1; j<nums.length;j++){
                if(nums[j-1]==0){
                    temp = nums[j];
                    nums[j] = nums[j-1];
                    nums[j-1] = temp;
                }
            }
        }
    }
}
